package go84;

public class Map {
	String _baseLoc;
	double _EAST, _WEST, _NORTH, _SOUTH;
	int _UTM_EAST, _UTM_WEST, _UTM_NORTH, _UTM_SOUTH, _UTM_ZONE;
	
	int _PXOffsetTop, _PXOffsetLeft;
	int _PXWidth, _PXHeight;
	int _segHeight, _segWidth;
	int _segments;
	int _zoom;
	int _maxZoom;
	String _mapName;
	public int _maxForcedZoom;
	public String _fileNamePrefix;
	UTM.Datum _datum;
	int _gridStartValue;
	public String _gridSep;
	public void updateZoom(int zoom){
		_zoom=zoom;
	}
	
	public Map(int pxWidth, int pxHeight, int pxOffsetTop, int pxOffsetLeft,
			double NORTH, double SOUTH, double EAST, double WEST, int segmentWidth,
			int segmentHeight, String baseLoc,String mapName,int maxZoom, UTM.Datum datum,String fileNamePrefix,
			int gridStartValue,String gridSep) {
		_gridSep=gridSep;
	
		_gridStartValue=gridStartValue;
		_fileNamePrefix=fileNamePrefix;
		_datum=datum;
		_maxForcedZoom=2;
		_segments=2;
		
		_PXWidth = pxWidth;
		_PXHeight = pxHeight;
		_PXOffsetTop = pxOffsetTop;
		_PXOffsetLeft = pxOffsetLeft;

		_EAST = EAST;
		_WEST = WEST;
		_NORTH = NORTH;
		_SOUTH = SOUTH;
		if(EAST<WEST)
			System.out.println("ERROR : EAST<WEST");
		if(NORTH<SOUTH)
			System.out.println("ERROR : NORTH<SOUTH");
		_segHeight = segmentHeight;
		_segWidth = segmentWidth;

		_baseLoc = baseLoc;
		
		System.out.println("MAP : "+_EAST+" "+_NORTH);
		double[] temp = new double[4];
		Convertor.toUTM(WEST,NORTH, temp);
		_UTM_WEST=(int)temp[0];
		_UTM_NORTH=(int)temp[1];
		
		Convertor.toUTM(EAST,SOUTH , temp);
		_UTM_EAST=(int)temp[0];
		_UTM_SOUTH=(int)temp[1];
		
		_UTM_ZONE=(int)temp[2];
		System.out.println("MAP : "+_UTM_EAST+" "+_UTM_NORTH);
		
		_mapName=mapName;
		_maxZoom=maxZoom;
	}

	public double getUTMCord2PxRatio(boolean isNorth,int zoom) {
		if (isNorth)
			return Math.abs((_UTM_NORTH) - (_UTM_SOUTH)) / (_PXHeight*Convertor.mathpow(2, (zoom==-1?_zoom:zoom)));
		return Math.abs((_UTM_EAST) - (_UTM_WEST)) / (_PXWidth*Convertor.mathpow(2, (zoom==-1?_zoom:zoom)));
	}

/*	public Pos getOnMapLocation(int UTM_EAST, int UTM_NORTH) {
		return new IntCanvas.Pos((_UTM_WEST - UTM_EAST)
				* getPx2CordRatio(false), (_UTM_SOUTH - UTM_NORTH)
				* getPx2CordRatio(true));

	}*/

	public double getUTMPx2CordRatio(boolean isNorth,int zoom) {
		return 1 / getUTMCord2PxRatio(isNorth,zoom);
	}

}